package com.sunagy.demand.backend.utils;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * desc：#TODO fill me ！
 * author：三餘無夢生
 * date：2018/4/27
 * time：下午2:48
 */
public class ValidUtil {
    public ValidUtil() {
    }

    public static boolean phoneNumber(String phoneNumber) {
        if (phoneNumber != null && !"".equals(phoneNumber)) {
            phoneNumber = phoneNumber.trim();
            String regExp = "^1\\d{10}$|^(0\\d{2,3}-?|\\(0\\d{2,3}\\))?[1-9]\\d{4,7}(-\\d{1,8})?$";
            Pattern p = Pattern.compile(regExp);
            Matcher m = p.matcher(phoneNumber);
            boolean flag = m.matches();
            return flag;
        } else {
            return false;
        }
    }

    public static boolean isChinaPhone(String phone) {
        if (Objects.equals(phone, "")) {
            return false;
        } else {
            Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[5,7])|(17[0-8]))\\d{8}$");
            Matcher m = p.matcher(phone);
            return m.matches();
        }
    }

    public static boolean email(String email) {
        if (email != null && !"".equals(email) && email.indexOf("@") != -1) {
            email = email.trim();
            String regExp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
            Pattern p = Pattern.compile(regExp);
            Matcher m = p.matcher(email);
            boolean flag = m.matches();
            return flag;
        } else {
            return false;
        }
    }
}
